package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class UpdateUserDemo {
    public static void main(String[] args) throws Exception {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo());
        Connection connection = DBUtil.getConnection();
        Statement statement = connection.createStatement();
        String sql = "UPDATE userinfo " +
                     "SET password = '" + userInfo.getPassWord() + "',nickname = '" + userInfo.getNickName() + "' " +
                     "WHERE username = '"+userInfo.getUserName()+"'";

        int num = statement.executeUpdate(sql);
        System.out.println(sql);
        System.out.println(num > 0 ? "修改成功!" : "用户名不存在!");
        connection.close();
    }

}
